/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.bean;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

/**
 * 说明：
 * Entity Name 定单
 * @Author：李智深
 * @Date：2012-03-14
 */
@Entity
@Table(name="ruipeng_tb_TOrder")
public class TOrder implements Serializable, TBehavior{
	
	private static final long serialVersionUID = 1L;
	
	private String OrderID;//定单编号CHAR(15)PK   //
	
	private byte Status;//TINYINT定单状态1为开始创建的定单 2为确认定单 3为已确定支付方式 4为定单已分配（确认货源） 5为定单正在执行调度 6为定单已发货 7为定单已完成 该字节的10位为撤消标记 0为没有撤消，1为正在撤消
	
	private byte PayWay;//付款方式TINYINT  0为尚未支付 1为店付通支付 2为支付宝支付 3为网银支付 4为货到付款  	7现金消费 8会员卡消费 9 刷卡消费";
	
	private byte PayStatus;//支付状态 1为未支付 2为已支付   //
	
	private byte SendWay;//配送方式  1为送货上门 2为物流 3店内取货
	
	private byte EndWay;//结束方式0为未设置 1为成功完成 2为已合并 3为已取消 4为卖家已取消 5为卖家无法送抵（比如说买家不要了）
	
	private double TotalAmount;//总金额DECIMAL(20,3)
	
	private double NeedMoney;//应支付金额
	
	private double PayedAmount;//已支付金额
	
	private Double CachPayedAmount;//会员卡支付金额
	
	private double DiscountAmount;//优惠金额
	
	private String PayID;//支付单编号 CHAR(15)
	
	private byte OrderType;//定单类型 TINYINT 1为个人定单 21为企业定单（个人支付） 22为企业定单（企业支付） 3为楼宇定餐定单，当类型为3时，群组编号为定单生成时的位置编号
	
	private byte CommentStatus;//评价状态 十位为1商店是否已评价，0为未评价 个位为1商品是否已评价，0为未评价
	
	private String CancelReason;//取消原因 VARCHAR(256)
	
	private String Note;//定单备注 VARCHAR(512)
	
	private String Type;//订单类型CHAR(18)1为零售 2为批发 
	
	private String Saler;//销售人CHAR(15)
	
	private String Operator;//操作人CHAR(15) //
	
	private Date HappenTime=new Date();//操作时间DATETIME  //
	
	private byte BillType;//票据类型TINYINT 1为收据  2为发票
	
	private String Invoice;//发票号VARCHAR(30)
	
	private double CardPayedAmount;//会员卡支持金额DECIMAL(20,3)
	
	private byte Source;//订单来源 1为店内订单2为网络订单
	
	private TUser TUser;//用户  //
	
	private TSendInfo TSendInfo;//配送地址
	
	private Date endTime;//结束时间  查询条件 不进数据库
	
	private double DLPayedAmount;//店联通支付金额
	
	private double BankCardPayedAmount;//银行卡支付金额
	
	private double CashCardPayedAmount;//优惠券金额
	
	private String WorkShiftID;//批次号
	
//	private Set<TOrderRefund> TOrderRefund=new HashSet<TOrderRefund>(0);//退款
	
	private TComment TComment;//=new TComment();//我的评论
	
	private int PersonCount;           //消费人数INTEGER NULL,x=
	private String PosID;                 //消费实施场所CHAR(15) NULL,  //
	private String RelID;                 //来源相关编号CHAR(15) NULL,
	
	private boolean isSelect;//不进数据库 是否选中
	private boolean isMainorder;//不进数据库 是否选中
	private String Operatorname;//操作人姓名
	private String TUsername;//用户名姓名
	private String Posname;
	
	@Transient
	public String getPosname() {
		return Posname;
	}
	public void setPosname(String posname) {
		Posname = posname;
	}

	public TOrder() {
		super();
	}
	
	@Transient
	public String getOperatorname() {
		return Operatorname;
	}
	public void setOperatorname(String operatorname) {
		Operatorname = operatorname;
	}

	@Transient
	public String getTUsername() {
		return TUsername;
	}
	public void setTUsername(String tUsername) {
		TUsername = tUsername;
	}

	public TOrder(String orderID) {
		super();
		OrderID = orderID;
	}

	@Id
	@Column(name = "OrderID", length=15)
	public String getOrderID() {
		return OrderID;
	}

	public void setOrderID(String orderID) {
		OrderID = orderID;
	}

	@Column(name = "Status")
	public byte getStatus() {
		return Status;
	}

	public void setStatus(byte status) {
		Status = status;
	}

	@Column(name = "PayWay")
	public byte getPayWay() {
		return PayWay;
	}

	public void setPayWay(byte payWay) {
		PayWay = payWay;
	}

	@Column(name = "PayStatus")
	public byte getPayStatus() {
		return PayStatus;
	}

	public void setPayStatus(byte payStatus) {
		PayStatus = payStatus;
	}

	@Column(name = "SendWay")
	public byte getSendWay() {
		return SendWay;
	}

	public void setSendWay(byte sendWay) {
		SendWay = sendWay;
	}

	@Column(name = "EndWay")
	public byte getEndWay() {
		return EndWay;
	}

	public void setEndWay(byte endWay) {
		EndWay = endWay;
	}

	@Column(name = "TotalAmount", precision = 20, scale = 3)
	public double getTotalAmount() {
		return TotalAmount;
	}

	public void setTotalAmount(double totalAmount) {
		TotalAmount = totalAmount;
	}

	@Column(name = "NeedMoney", precision = 20, scale = 3)
	public double getNeedMoney() {
		return NeedMoney;
	}

	public void setNeedMoney(double needMoney) {
		NeedMoney = needMoney;
	}

	@Column(name = "PayedAmount", precision = 20, scale = 3)
	public double getPayedAmount() {
		return PayedAmount;
	}

	public void setPayedAmount(double payedAmount) {
		PayedAmount = payedAmount;
	}
	@Column(name = "CachPayedAmount", precision = 20, scale = 3)
	public Double getCachPayedAmount() {
		if(CachPayedAmount==null){
			return 0.0;
		}
		return CachPayedAmount;
	}

	public void setCachPayedAmount(Double cachPayedAmount) {
		CachPayedAmount = cachPayedAmount;
	}

	@Column(name = "DiscountAmount", precision = 20, scale = 3)
	public double getDiscountAmount() {
		return DiscountAmount;
	}

	public void setDiscountAmount(double discountAmount) {
		DiscountAmount = discountAmount;
	}

	@Column(name = "PayID", length=15)
	public String getPayID() {
		return PayID;
	}

	public void setPayID(String payID) {
		PayID = payID;
	}

	@Column(name = "OrderType")
	public byte getOrderType() {
		return OrderType;
	}

	public void setOrderType(byte orderType) {
		OrderType = orderType;
	}

	@Column(name = "CommentStatus")
	public byte getCommentStatus() {
		return CommentStatus;
	}

	public void setCommentStatus(byte commentStatus) {
		CommentStatus = commentStatus;
	}

	@Column(name = "CancelReason", length=256)
	public String getCancelReason() {
		return CancelReason;
	}

	public void setCancelReason(String cancelReason) {
		CancelReason = cancelReason;
	}

	@Column(name = "Note", length=15)
	public String getNote() {
		return Note;
	}

	public void setNote(String note) {
		Note = note;
	}

	@Column(name = "Source")
	public byte getSource() {
		return Source;
	}

	public void setSource(byte source) {
		Source = source;
	}

	@Column(name = "Type", length=18)
	public String getType() {
		return Type;
	}

	public void setType(String type) {
		Type = type;
	}

	@Column(name = "Saler", length=15)
	public String getSaler() {
		return Saler;
	}

	public void setSaler(String saler) {
		Saler = saler;
	}

	@Column(name = "Operator", length=15)
	public String getOperator() {
		return Operator;
	}

	public void setOperator(String operator) {
		Operator = operator;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "HappenTime", nullable = false, length = 19)
	public Date getHappenTime() {
		return HappenTime;
	}

	public void setHappenTime(Date happenTime) {
		HappenTime = happenTime;
	}

	@Column(name = "BillType")
	public byte getBillType() {
		return BillType;
	}

	public void setBillType(byte billType) {
		BillType = billType;
	}

	@Column(name = "Invoice", length=30)
	public String getInvoice() {
		return Invoice;
	}

	public void setInvoice(String invoice) {
		Invoice = invoice;
	}

	@Column(name = "CardPayedAmount", precision = 20, scale = 3)
	public double getCardPayedAmount() {
		return CardPayedAmount;
	}

	public void setCardPayedAmount(double cardPayedAmount) {
		CardPayedAmount = cardPayedAmount;
	}
	

	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="UserID")
	public TUser getTUser() {
		return TUser;
	}

	public void setTUser(TUser tUser) {
		TUser = tUser;
	}
	@ManyToOne
	@JoinColumn(name="SendInfoID")
	public TSendInfo getTSendInfo() {
		return TSendInfo;
	}

	public void setTSendInfo(TSendInfo tSendInfo) {
		TSendInfo = tSendInfo;
	}
	@Transient
	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	@Column(name = "WorkShiftID", length=15)
	public String getWorkShiftID() {
		return WorkShiftID;
	}

	public void setWorkShiftID(String workShiftID) {
		WorkShiftID = workShiftID;
	}


	@Override
	@Transient
	public Date getBHappenTime() {
		return this.HappenTime;
	}

//	@Override
//	@Transient
//	public byte getBSource() {
//		return this.Source;
//	}

	@Override
	@Transient
	public String getBUserID() {
		return this.TUser.getUserName();
	}

	@Override
	@Transient
	public BehaviorType getBType() {
		return BehaviorType.BehaviorBuy;
	}

	@Override
	@Transient
	public String getBTypeName() {
		return "购买";
	}
	
//	@OneToMany(mappedBy="TOrder")
//	@JoinColumn(name="OrderID")
//	public Set<TOrderRefund> getTOrderRefund() {
//		return TOrderRefund;
//	}
//
//	public void setTOrderRefund(Set<TOrderRefund> tOrderRefund) {
//		TOrderRefund = tOrderRefund;
//	}
	
	@OneToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="CommentID")
	public TComment getTComment() {
		return TComment;
	}

	public void setTComment(TComment comment) {
		TComment = comment;
	}

	@Column(name = "DLPayedAmount", precision = 20, scale = 3)
	public double getDLPayedAmount() {
		return DLPayedAmount;
	}

	public void setDLPayedAmount(double dLPayedAmount) {
		DLPayedAmount = dLPayedAmount;
	}

	@Column(name = "BankCardPayedAmount", precision = 20, scale = 3)
	public double getBankCardPayedAmount() {
		return BankCardPayedAmount;
	}

	public void setBankCardPayedAmount(double bankCardPayedAmount) {
		BankCardPayedAmount = bankCardPayedAmount;
	}

	@Column(name = "CashCardPayedAmount", precision = 20, scale = 3)
	public double getCashCardPayedAmount() {
		return CashCardPayedAmount;
	}

	public void setCashCardPayedAmount(double cashCardPayedAmount) {
		CashCardPayedAmount = cashCardPayedAmount;
	}

	@Column(name = "PersonCount")
	public int getPersonCount() {
		return PersonCount;
	}

	public void setPersonCount(Integer personCount) {
		if (personCount == null)
			PersonCount = 0;
		else
			PersonCount = personCount;
	}

	@Column(name = "PosID", length=15)
	public String getPosID() {
		return PosID;
	}

	public void setPosID(String posID) {
		PosID = posID;
	}

	@Column(name = "RelID", length=15)
	public String getRelID() {
		return RelID;
	}

	public void setRelID(String relID) {
		RelID = relID;
	}
	
	@Transient
	public boolean isSelect() {
		return isSelect;
	}
	public void setSelect(boolean isSelect) {
		this.isSelect = isSelect;
	}

	@Transient
	public boolean isMainorder() {
		return isMainorder;
	}
	public void setMainorder(boolean isMainorder) {
		this.isMainorder = isMainorder;
	}


}
